<?php
	function parse_name($name)
	{
		preg_match('/(?P<last>[a-zA-Z\-\s]+)\,\s(?P<first>[a-zA-Z\-\s]+)/', $name, $match);
		
		if (isset($match['first']) && isset($match['last'])) {
			$first = $match['first'];
			$last = $match['last'];
			return $first." ".$last;
		}
		return "";
	}
	
	function parse_char($name)
	{
		$char = "";
		$num = 9999;
		if (is_numeric($offset = strpos($name, "["))) {
			$char = substr($name, $offset + 1, strpos($name, "]") - $offset - 1);
		}
		if (is_numeric($offset = strpos($name, "<"))) {
			$num = substr($name, $offset + 1, strpos($name, ">") - $offset - 1);
		}
		return array("char" => $char, "num" => $num);
	}
	
	function character_comp($a, $b) {
		return $a['character']['num'] - $b['character']['num'];
	}
    
    if (isset($session->userinfo["id"])) {
        echo "<script>myid = ".$session->userinfo["id"].";</script>";
    }
    
    echo "<script>entities = { Genre: 0, Director: 1, Writer: 2, Actor: 3 }</script>";
	
	$genreId = array("Action",
					"Adult",
					"Adventure",
					"Animation",
					"Biography",
					"Comedy",
					"Crime",
					"Documentary",
					"Drama",
					"Family",
					"Fantasy",
					"Film-Noir",
					"History",
					"Horror",
					"Music",
					"Musical",
					"Mystery",
					"Romance",
					"Sci-Fi",
					"Short",
					"Sport",
					"Thriller",
					"War",
					"Western");
?>